package wirepack

import "log"

// 数据最大长度，超过此长度数据丢弃
const MaxPacketLen = (1024 * 100)

type WirePack interface {
	// 数据包打包为传输数据
	Pack([]byte) []byte
	Protocol() string
}

type WireUnpack interface {
	// 解包数据，返回数据包列表
	Decode([]byte) [][]byte
}

func NewWirePack(name string) WirePack {
	switch name {
	case BASE64CRLN:
		return NewBase64CrLf()
	case LINEPACK:
		return NewLinePkt()
	case LENPKT:
		return NewLenPkt()
	case SBMLLPEBCR:
		return NewSbMllpEbCrPkt()
	}
	log.Fatal("NewWirePack Unsupport protocol", name)
	return nil
}

func NewWireUnpack(name string) WireUnpack {
	switch name {
	case BASE64CRLN:
		return NewBase64CrLf()
		// case LENPKT:
		// 	return NewLenPkt()
	case LINEPACK:
		return NewLinePkt()
	case SBMLLPEBCR:
		return NewSbMllpEbCrPkt()
	}

	log.Fatal("NewDataUnpack Unsupport protocol", name)
	return nil
}
